// 所有关于视频模块的vuex 
import { getVideoList } from '../../api/video'
const videoStore = {
  namespaced: true,
  state: {
    videoFlag: false,
    videoList: [],//视频列表的数据
    pageSize: 0,
    total: 0,
    pageStart: 1,
    endPage: 0,
    editRow: {
      ID: "",
      Vname: "",
      Vurl: "",
      Vtime: ""
    },//修改行数据
  },
  mutations: {
    changeVideoFlag (state, flag) {  //改变视频上传弹出层的mutations
      state.videoFlag = flag;
    },
    changeData (state, res) {
      if (res.err) {
        state.videoList = [];
      } else {
        state.videoList = res.data.list;
        state.pageSize = res.data.pageSize;
        state.total = res.data.count;
        state.endPage = Math.ceil(res.data.count / res.data.pageSize);

      }
    },
    changePage (state, page) { //改变当前页码
      state.pageStart = page;
    },
    changeEditRow (state, row) {
      state.editRow = row;
    }
  },
  actions: {
    async getVideoAction ({ commit }, data) { //获取视频的actions
      var res = await getVideoList(data)
      console.log(res)
      commit("changeData", res)
      return Promise.resolve(res)
    }
  },
  getters: {
    videoFlag: state => state.videoFlag,
    videoList: state => state.videoList,
    pageSize: state => state.pageSize,
    total: state => state.total,
    pageStart: state => state.pageStart,
    endPage: state => state.endPage
  }
}
export default videoStore